<?php
apf_require_class('APF_Controller');
apf_require_class('Solr_Bll_AppBiz');
apf_require_class('Solr_Bll_ReportHostBiz');
apf_require_class('Solr_Util_PageBar');
class Report_HostListController extends APF_Controller {

    public static function build_uri() {
        $base_domain = APF::get_instance()->get_config("base_domain");
        $schema = APF::get_instance()->get_request()->is_secure() ? "https" : "http";
        $url = "{$schema}://{$base_domain}/report/hostlist/";
        return $url;
    }

    public function handle_request() {

        $request = APF::get_instance()->get_request();
        $params = $request->get_parameters();
        $page=max(intval($params['page']),1);
        $num = 50;

        $attr=array();
        if($params['datei'])$attr['datei']=$params['datei'];
        if($params['hostname_id'])$attr['hostname_id']=$params['hostname_id'];
        if($params['port'])$attr['port']=$params['port'];

        $host_report_list=Solr_Bll_ReportHostBiz::get_instance()->get_host_reports_list($attr,$page,$num);
        $host_report_count=Solr_Bll_ReportHostBiz::get_instance()->get_host_reports_count($attr);
        $request->set_attribute('host_report_list',$host_report_list);

        $hostnames=Solr_Bll_AppBiz::get_instance()->get_all_hostname();
        $request->set_attribute('hostnames',$hostnames);

        $var="datei=".$params['datei']."&hostname_id=".$params['hostname_id']."&port=".$params['port'];
        $page_bar=Solr_Util_PageBar::get_page_bar(Report_HostListController::build_uri(),$host_report_count,$page,$num,$var,'page',9);
        $request->set_attribute('page_bar',$page_bar);

        $request->set_attribute('params',$params);
        return 'Report_HostList';
    }
}

